﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RTNLip.Scripts
{
    class RTNDatabase //where T : new()
    {
        /// <summary>
        /// create table follow class design.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public void createTable<T>()
        {
            string ss = RTNSQLDataType.getSqlString<T>();
            Type tType = typeof(T);
            FieldInfo[] fields = tType.GetFields();
            foreach(FieldInfo f in fields)
            {
                MessageBox.Show(f.Name + " : " + RTNSQLDataType.getSqlStringType(f));
            }
        }

        /// <summary>
        /// open connection with overload method.
        /// </summary>
        /// <returns></returns>
        public static RTNDatabase Open()
        {
            return new RTNDatabase();
        }
        public static RTNDatabase Open(string severName,string dbName)
        {
            return new RTNDatabase();
        }
        public static RTNDatabase Open(string pathFileName,string dbName,bool isDBFile)
        {
            return new RTNDatabase();
        }
        public static RTNDatabase Open(string serverName,string dbName,string userName,string passWord)
        {
            return new RTNDatabase();
        }
        public static RTNDatabase Open(string serverIP,string networkLip,string dbName,string userName , string passWord)
        {
            return new RTNDatabase();
        }
        public void Close()
        {

        }
       
        /// <summary>
        /// optimize connection and database.
        /// </summary>
        public void Optimize()
        {

        }
        public string setupTable<T>() where T : new()
        {
            return null;
        }
        public void dynamicSQL(string sqlText)
        {

        }

        /// <summary>
        /// get record from tables
        /// </summary>
        /// <typeparam name="T"> Type of class </typeparam>
        /// <returns>record of T type </returns>
        public T getSingleRecord<T>()where T : class,new()
        {
            return default(T);
        }
        public T getSingleRecord<T>(string whereText, string groupText, string orderText, string limitText) where T : class,new()
        {
            return default(T);
        }
        public T getFirstRecord<T>()
        {
            return default(T);
        }
        public T getLastRecord<T>()
        {
            return default(T);
        }
        public T[] getRecord<T>()where T : new()
        {
            return null;
        }
        public T[] getRecord<T>(string whereText, string groupText, string orderText, string limitText)where T : new()
        {
            return null;
        }

        /// <summary>
        /// set method
        /// </summary>
        /// <typeparam name="T">type of class</typeparam>
        /// <param name="obj">object of type T</param>
        public void setSingleRecord<T>(T obj)
        {
            Type tType = typeof(T);
            FieldInfo[] fields = tType.GetFields();
            foreach(FieldInfo f in fields)
            {
                MessageBox.Show("Field : " + f.Name + " Value : " + f.GetValue(obj));
            }
        }
        public void setRecord<T>(T obj) where T : new()
        {
            Type tType = typeof(T);
            FieldInfo[] fields = tType.GetFields();
            foreach(FieldInfo f in fields)
            {
                MessageBox.Show(f.Name + " : " + f.GetValue(obj));
            }
        }
        public void setRecord<T>(T[] objs) where T : new()
        {
            foreach(T obj in objs)
                this.setRecord<T>(obj);
        }

        /// <summary>
        /// update record
        /// </summary>
        /// <typeparam name="T"> type of class </typeparam>
        /// <param name="obj"> object type of T </param>
        public void updateRecord<T>(T obj)
        {

        }
        public void updateRecord<T>(T[] obj)
        {

        }

        /// <summary>
        /// delete record
        /// </summary>
        /// <typeparam name="T"> type of class </typeparam>
        public void deleteRecord<T>(string whereText)
        {

        }
        public void deleteTable<T>()
        {

        }
    }
}
